package com.pospi.img;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.Target;

import java.io.File;

/**
 * Created by acer on 2018/8/29.
 */


public class DownLoadImageService implements Runnable {

    private String url;

    private Context context;

    private ImageDownLoadCallBack callBack;


    public DownLoadImageService(Context context, String url, ImageDownLoadCallBack callBack) {

        this.url = url;

        this.callBack = callBack;

        this.context = context;

    }


    @Override

    public void run() {

        File file = null;

        try {

            file = Glide.with(context)

                    .load(url)

                    .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)

                    .get();

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            if (file != null) {

                callBack.onDownLoadSuccess(file);

            } else {

                callBack.onDownLoadFailed();

            }

        }

    }


}

